//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.yaukie.base.config;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.servlet.DispatcherType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.yaukie.base.config.properties.XssConfigProperties;
import org.yaukie.base.core.filter.XssFilter;
import org.yaukie.base.text.Convert;
import org.yaukie.base.util.StringTools;

@Configuration
public class SysConfig {
    private static final Logger log = LoggerFactory.getLogger(SysConfig.class);
    @Value("${spring.redis.enabled:false}")
    private String enabled;
    @Value("${kettle.pool.coreThreads}")
    private int coreThreads;
    @Value("${kettle.pool.maxThreads}")
    private int maxThreads;
    @Value("${kettle.pool.queueCapacity}")
    private int queueCapacity;

    public SysConfig() {
    }

    @PostConstruct
    public void init() {
        log.info("===系统线程池初始化参数===\r\n===可支持核心线程数--{}===\r\n===最大自定义线程数--{}===\r\n===最大自定义队列容量--{}===", new Object[]{this.coreThreads, this.maxThreads, this.queueCapacity});
        if (Convert.toBool(this.enabled)) {
            log.info("===系统将启用REDIS作为缓存===\r\n");
        } else {
            log.info("===系统将启用MAP作为缓存,最大可支持1024个缓存KEY,请慎重选择===\r\n");
        }

    }

    @Bean
    public FilterRegistrationBean xssFilterRegistration(XssConfigProperties xssConfigProperties) {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST, new DispatcherType[0]);
        registration.setFilter(new XssFilter());
        registration.addUrlPatterns(StringTools.split(xssConfigProperties.getUrlPatterns(), ","));
        registration.setName("xssFilter");
        registration.setOrder(Integer.MIN_VALUE);
        Map<String, String> initParameters = new HashMap();
        initParameters.put("excludes", xssConfigProperties.getExcludes());
        initParameters.put("enabled", xssConfigProperties.getXssEnabled());
        registration.setInitParameters(initParameters);
        return registration;
    }
}
